package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import Controleur.GestionnaireSimulateur;
import Domaine.Noeud;


public class FenetreAjoutUrgence extends JDialog {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3616833348661836720L;
	private JLabel tempsLabel;
	private JTextField temps;
	private JLabel dateLabel;
	private JTextField date;
	private JButton ok;
	private JButton annuler;
	private SpringLayout layout;
	
	private GestionnaireSimulateur controlleur;
	private Noeud n; // Le noeud auquel on va ajouter l'urgence.
	
	public FenetreAjoutUrgence(GestionnaireSimulateur ctrl, Noeud node) {
		
		this.controlleur = ctrl;
		this.n = node;
		
		this.setSize(350, 160);
		this.setAlwaysOnTop(true);
		this.setTitle("Ajouter une urgence");
		this.setLocationRelativeTo(null);
		//this.setResizable(false);
		
		this.tempsLabel = new JLabel("Temps de traitement : ");
		this.temps = new JTextField();
		this.dateLabel = new JLabel("yyyy-MM-dd HH:mm:ss");
		this.date = new JTextField();

		this.ok = new JButton("Ok");
		this.annuler = new JButton("Annuler");
		
		this.layout = new SpringLayout();
		
		// Construction de la fen�tre.
		this.getContentPane().setLayout(this.layout);
		
		this.getContentPane().add(this.tempsLabel);
		this.getContentPane().add(this.temps);
		this.getContentPane().add(this.dateLabel);
		this.getContentPane().add(this.date);
		this.getContentPane().add(this.ok);
		this.getContentPane().add(this.annuler);
		
		this.layout.putConstraint(SpringLayout.SOUTH, this.annuler, -15, SpringLayout.SOUTH, this.getContentPane());
		this.layout.putConstraint(SpringLayout.EAST, this.annuler, -15, SpringLayout.EAST, this.getContentPane());
		
		this.layout.putConstraint(SpringLayout.SOUTH, this.ok, -15, SpringLayout.SOUTH, this.getContentPane());
		this.layout.putConstraint(SpringLayout.EAST, this.ok, -5, SpringLayout.WEST, this.annuler);
		
		this.layout.putConstraint(SpringLayout.WEST, this.tempsLabel, 15, SpringLayout.WEST, this.getContentPane());
		this.layout.putConstraint(SpringLayout.NORTH, this.tempsLabel, 15, SpringLayout.NORTH, this.getContentPane());
		
		this.layout.putConstraint(SpringLayout.EAST, this.temps, -15, SpringLayout.EAST, this.getContentPane());
		this.layout.putConstraint(SpringLayout.WEST, this.temps, 20, SpringLayout.EAST, this.tempsLabel);
		this.layout.putConstraint(SpringLayout.NORTH, this.temps, 0, SpringLayout.NORTH, this.tempsLabel);
		
		this.layout.putConstraint(SpringLayout.SOUTH, this.dateLabel, -5, SpringLayout.NORTH, this.annuler);
		this.layout.putConstraint(SpringLayout.WEST, this.dateLabel, 0, SpringLayout.WEST, this.tempsLabel);
		
		this.layout.putConstraint(SpringLayout.SOUTH, this.date, -5, SpringLayout.NORTH, this.annuler);
		this.layout.putConstraint(SpringLayout.EAST, this.date, 0, SpringLayout.EAST, this.temps);
		this.layout.putConstraint(SpringLayout.WEST, this.date, 0, SpringLayout.WEST, this.temps);
		
		this.ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				controlleur.ajouterUrgence(n, date.getText(), temps.getText());
				setVisible(false);
			}
			
		});
	}
}